package cn.etynit.web.controller;

import cn.etynit.domain.Employee;
import cn.etynit.dto.*;
import cn.etynit.query.EmployeeQuery;
import cn.etynit.result.JsonResult;
import cn.etynit.result.PageList;
import cn.etynit.service.IEmployeeService;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.plugins.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/employee")
@Api(value = "员工接口",description = "此接口是员工相关的类")
public class EmployeeController {

    @Autowired
    public IEmployeeService employeeService;

    /**
    * 保存和修改公用的
    */
    @ApiOperation(value = "保存和修改员工",notes = "保存和修改员工",response = JsonResult.class)
    @RequestMapping(value="/save",method= RequestMethod.POST)
    public JsonResult saveOrUpdate(@RequestBody Employee employee){
        if(employee.getId()!=null){
            employeeService.updateById(employee);
        }else{
            employeeService.insert(employee);
        }
        return JsonResult.success();
    }

    /**
    * 删除对象
    */
    @ApiOperation(value = "根据id删除员工",notes = "根据id删除员工",response = JsonResult.class)
    @RequestMapping(value="/{id}",method=RequestMethod.DELETE)
    public JsonResult delete(@PathVariable("id") Long id){
        employeeService.deleteById(id);
        return JsonResult.success();
    }

    /**
   * 获取对象
   */
    @ApiOperation(value = "根据id查询员工",notes = "根据id查询员工",response = JsonResult.class)
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public JsonResult get(@PathVariable("id")Long id){
        return JsonResult.success(employeeService.selectById(id));
    }


    /**
    * 查询所有对象
    */
    @ApiOperation(value = "查询所有员工",notes = "查询所有员工",response = JsonResult.class)
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public JsonResult list(){
        return JsonResult.success(employeeService.selectList(null));
    }


    /**
    * 带条件分页查询数据
    */
    @ApiOperation(value = "分页查询所有员工",notes = "分页查询所有员工",response = JsonResult.class)
    @RequestMapping(value = "/pagelist",method = RequestMethod.POST)
    public JsonResult page(@RequestBody EmployeeQuery query){
        Page<Employee> page = new Page<Employee>(query.getPage(),query.getRows());
        page = employeeService.selectPage(page);
        return JsonResult.success(new PageList<Employee>(page.getTotal(),page.getRecords()));
    }

    /**
     * 账单生成
     * @param billDto
     * @return
     */
    @ApiOperation(value = "员工录入业主费用",notes = "员工录入业主费用",response = JsonResult.class)
    @RequestMapping(value="/billGeneration",method= RequestMethod.POST)
    public JsonResult billGeneration(@RequestBody BillDto billDto,String token){
        return JsonResult.success(employeeService.billGeneration(billDto,token));
    }

    /**
     * 社区活动发布
     * @param activityDto
     * @return
     */
    @ApiOperation(value = "发布社区活动",notes = "发布社区活动",response = JsonResult.class)
    @RequestMapping(value="/releaseActivity",method= RequestMethod.POST)
    public JsonResult releaseActivity(@RequestBody ActivityDto activityDto,String token){
        return JsonResult.success(employeeService.releaseActivity(activityDto,token));
    }

    /**
     * 业主办理停车位
     * @param parkingSpaceDto
     * @return
     */
    @ApiOperation(value = "业主办理停车位",notes = "办理停车位",response = JsonResult.class)
    @RequestMapping(value="/registerForParking",method= RequestMethod.POST)
    public JsonResult registerForParking(@RequestBody ParkingSpaceDto parkingSpaceDto,String token){
        return JsonResult.success(employeeService.registerForParking(parkingSpaceDto,token));
    }

    /**
     * 员工登录
     * @param accountLoginDto
     * @return
     */
    @ApiOperation(value = "员工登录",notes = "员工登录",response = JsonResult.class)
    @RequestMapping(value="/accountLogin",method= RequestMethod.POST)
    public JsonResult accountLogin(@RequestBody AccountLoginDto accountLoginDto){
        return JsonResult.success(employeeService.accountLogin(accountLoginDto));
    }

    /**
     * 通知发布
     * @param informPublishDto
     * @return
     */
    @ApiOperation(value = "通知发布",notes = "通知发布",response = JsonResult.class)
    @RequestMapping(value="/informPublish/{token}",method= RequestMethod.POST)
    public JsonResult informPublish(@RequestBody InformPublishDto informPublishDto,@PathVariable("token") String token){
        return JsonResult.success(employeeService.informPublish(informPublishDto,token));
    }
}
